const express = require('express')
const md5 = require('md5')
const adminModel = require('../db/model/adminModel')

const router = express.Router()

router.post('/addAdmin', async (req, res) => {
  const { username, password } = req.body
  await adminModel.create({ username, password: md5(password) })
  res.send({ success: true, msg: '添加成功' })
})
router.get('/findAdmins', async (req, res) => {
  try {
    const result = await adminModel.find({}, { password: 0 })
    res.send({ success: true, msg: '查找成功', data: result })
  } catch (error) {
    res.send({ success: false, msg: '网络错误,请稍后再试' })
  }
})

module.exports = router
